package com.shan.mybatis.mapper;

import com.shan.mybatis.pojo.Emp;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    @Select("select * from emp")
    List<Emp> list();
//    @Select("select count(*) from emp")
//    Long count();
//
//    @Select("select * from emp limit #{start},#{pageSize} ")
//    public List<Emp> page(@Param("start") Integer start,@Param("pageSize") Integer pageSize);


    //删除员工
    @Delete("delete from emp where id=#{id}")
    void deleteById(Integer id);

    //添加员工
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into emp(username,name,gender,image,job,entrydate,dept_id,create_time,update_time) " +
            "values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime}) ")
    void addEmp(Emp emp);

    //修改员工

    void update(Emp emp);

    //查询员工通过id
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp where id=#{id}")
    Emp selectById(Integer id);

    //模糊查询
    List<Emp> selectLike(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    void deleteIds(List<Integer> ids);

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp getByUsernmaeAndPassword(Emp emp);
/*
    根据部门id，删除底下的员工
 */
    @Delete("delete from emp where dept_id=#{depId} ")
    void deleteByDeptId(Integer depId);
}